import { Body, Controller, Post, Query } from '@nestjs/common';
import { ApiOperation, ApiTags, ApiQuery } from '@nestjs/swagger';
import { WechatService, WechatMessageDto } from './wechat.service';
import { UploadMaterialDto, UploadNewsDto } from './dto/upload-material.dto';

@ApiTags('wechat')
@Controller('wechat')
export class WechatController {
  constructor(private readonly wechatService: WechatService) {}

  @Post('send')
  @ApiOperation({ summary: '发送微信消息' })
  async sendMessage(@Body() messageDto: WechatMessageDto) {
    return this.wechatService.sendMessage(messageDto);
  }

  @Post('upload/material')
  @ApiOperation({ summary: '上传素材到微信公众号' })
  @ApiQuery({
    name: 'isPermanent',
    required: false,
    type: Boolean,
    description: '是否为永久素材',
  })
  async uploadMaterial(
    @Body() uploadDto: UploadMaterialDto,
    @Query('isPermanent') isPermanent?: boolean,
  ) {
    return this.wechatService.uploadMaterial(uploadDto, isPermanent === true);
  }

  @Post('upload/news')
  @ApiOperation({ summary: '上传图文素材到微信公众号' })
  async uploadNews(@Body() uploadDto: UploadNewsDto) {
    return this.wechatService.uploadNews(uploadDto);
  }
}
